#include <iostream>
#include <vector>
using namespace std;
//责任链模式
enum class Answer {
    NO,YES
};
class GimmeStrategy{
    public:
    virtual Answer canIHave() = 0;
    virtual ~GimmeStrategy(){}
};
class AskMom:public GimmeStrategy{
    Answer canIHave(){
        cout << "AskMom" <<endl;
        return Answer::YES;
    }
};
class Askdad:public GimmeStrategy{
    Answer canIHave(){
        cout << "Askdad" <<endl;
        return Answer::YES;
    }
};
class AskGrandma:public GimmeStrategy{
    Answer canIHave(){
        cout << "AskGrandma" <<endl;
        return Answer::YES;
    }
};

class Gimme:public GimmeStrategy{
    vector<GimmeStrategy*> chain;
public:
    Gimme(){
        chain.push_back(new AskMom);
        chain.push_back(new Askdad);
        chain.push_back(new AskGrandma);
    }  
    
    // 核心：遍历责任链
    Answer canIHave(){
        vector<GimmeStrategy*> ::iterator it =chain.begin();
        while (it!=chain.end())
        {
            if((*it++)->canIHave()==Answer::YES){
               return Answer::YES;
            }
        }
        return Answer::NO;
    }
    ~Gimme(){

    }
};

int main(){
    Gimme chain;
    chain.canIHave();
    return 0;
}